package com.comp490.level;

import java.util.List;

import android.util.SparseArray;

import com.comp490.shooter.GameView;
import com.comp490.sprite.EnemySprite;

public class BaseLevel
{
    protected GameView gameView;
    protected SparseArray<WaveStruct> enemyWaveSet;
    protected int currentWave;
    protected int numOfWavesFinished;
    protected int totalNumberofWaves;
    protected boolean bossFight;
    
    public BaseLevel(GameView gameView)
    {
        this.gameView = gameView;
        enemyWaveSet = new SparseArray<WaveStruct>();
        currentWave = -1;
        numOfWavesFinished = 0;
        totalNumberofWaves = 0;
        bossFight = false;
    }
    
    protected boolean isSomeoneAlive()
    {
    	for(int i = 0; i < enemyWaveSet.get(currentWave).getEnemySet().size(); i++)
    	{
            if(enemyWaveSet.get(currentWave).getEnemySet().get(i).isActive() || enemyWaveSet.get(currentWave).getEnemySet().get(i).isExploding())
                return true;
    	}
        return false;
    }

    protected class WaveStruct
    {
        protected int enemyCycles;
        private boolean firstPass;
        private List<EnemySprite> enemySet;

        public WaveStruct(int enemyCyles, List<EnemySprite> enemySet)
        {
            this.enemyCycles = enemyCyles;
            this.enemySet = enemySet;
            firstPass = true;
        }

        public boolean isFirstPass()
        {
            return firstPass;
        }

        public void decrementCycle()
        {
            this.enemyCycles--;
            if(firstPass)
                firstPass = false;
            if(enemyCycles == 0)
                numOfWavesFinished++;
        }

        public List<EnemySprite> getEnemySet()
        {
            return enemySet;
        }
    }
}
